package com.homegoods.videomodule.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.cyt.chattlibrary.face.SmileyParser;
import com.homegoods.videomodule.R;
import com.homegoods.videomodule.item.CommentItem;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.mvp.BaseModel;
import com.kedll.library.util.DateUtil;
import com.kedll.library.util.MyUtils;

/**
 * @author QiQi
 * @ClassName: CommentModel
 * @date 2018/10/15
 * @description 评论
 */
public class CommentModel extends BaseModel<CommentItem> implements Parcelable {

    public static final Parcelable.Creator<CommentModel> CREATOR = new Parcelable.Creator<CommentModel>() {
        @Override
        public CommentModel createFromParcel(Parcel source) {
            return new CommentModel(source);
        }

        @Override
        public CommentModel[] newArray(int size) {
            return new CommentModel[size];
        }
    };


    /**
     * "num": "1",
     * 				"sid": "te%2fNudpSzNzaphd9cuvPA70YdxDuM5%2fqg2POmGd8FINx2oWu79L0JVvlIbYgnV%2bp",
     * 				"MsgBody": "123456",
     * 				"SubjectSid": "munityvideo_2182213ea47842e69961cfce98fd8ea6",
     * 				"ExtData": "",
     * 				"SenderSid": {
     * 					"headimg": "http://thirdqq.qlogo.cn/g?b=oidb\u0026k=d6dwO9E6mOVEevxNoib9DjA\u0026s=100",
     * 					"name": "兮夜"
     *                                },
     * 				"GoodVol": "24"
     */
    /**
     * 评论ID
     */
    @JSONField(alternateNames = {"sid"})
    private String id;

    /**
     * 发布评论的时间
     */
    @JSONField(alternateNames = {"ExtData"})
    private long time;

    private String SubjectSid;
    /**
     * 发表评论人的id
     */
    private String commenterId;
    /**
     * 评论内容
     */
    @JSONField(alternateNames = {"MsgBody"})
    private String comment;

    private SenderSidBean SenderSid;
    /**
     * 回复数
     */
    private String replyCount;
    /**
     * 点赞数
     */
    @JSONField(alternateNames = {"GoodVol"})
    private String goodCount;
    /**
     * 查看人是否点过赞
     */
    private int hasGood;

    public CommentModel() {
    }

    protected CommentModel(Parcel in) {
        this.id = in.readString();
        this.time = in.readLong();
        this.commenterId = in.readString();
        this.comment = in.readString();
        this.replyCount = in.readString();
        this.goodCount = in.readString();
        this.hasGood = in.readInt();
    }

    public String getId() {
        return id == null ? "" : id;
    }

    public void setId(String id) {
        this.id = id;
    }


    public String getTime() {
        return DateUtil.friendlyTime(time);
    }

    public void setTime(long time) {
        this.time = time;
    }

    public String getCommenterId() {
        return commenterId == null ? "" : commenterId;
    }

    public void setCommenterId(String commenterId) {
        this.commenterId = commenterId;
    }

    public SpannableStringBuilder getComment() {
        return SmileyParser.getInstance().addSmileySpans(comment, MyUtils.dp2px(16));
    }

    public void setComment(String comment) {
        this.comment = comment;
    }


    public String getReplyCount() {
        return (TextUtils.isEmpty(replyCount) || "0".equals(replyCount)) ? "回复" : String.format("%s回复", replyCount);
    }

    public void setReplyCount(String replyCount) {
        this.replyCount = replyCount;
    }

    public String getGoodCount() {
        return "0".equals(goodCount) ? "赞" : goodCount;
    }

    public void setGoodCount(String goodCount) {
        this.goodCount = goodCount;
    }

    public int getHasGood() {
        return hasGood == 0 ? R.mipmap.good : R.drawable.video_good_red;
    }

    public void setHasGood(int hasGood) {
        this.hasGood = hasGood;
    }

    public String getSubjectSid() {
        return SubjectSid;
    }

    public void setSubjectSid(String subjectSid) {
        SubjectSid = subjectSid;
    }

    public SenderSidBean getSenderSid() {
        return SenderSid;
    }

    public void setSenderSid(SenderSidBean senderSid) {
        SenderSid = senderSid;
    }

    @Override
    public CommentItem createItem(MultiTypeAdapter adapter) {
        return new CommentItem(this, adapter);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeLong(this.time);
        dest.writeString(this.commenterId);
        dest.writeString(this.comment);
        dest.writeString(this.replyCount);
        dest.writeString(this.goodCount);
        dest.writeInt(this.hasGood);
    }

}
